// Copyright 2007 Google Inc.  All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.enterprise.onebox.apps;

import com.google.enterprise.onebox.apps.SimpleOneBoxResults.ModuleResult;

import junit.framework.TestCase;

/**
 * This class is a test case that verifies several properties of the
 * SimpleOneBoxResults implementation, namely:
 * (1) A configured results set matches a golden output in string form.
 * 
 * @author amsmith@google.com (Adam Smith)
 */
public class SimpleOneBoxResultsTest extends TestCase {

  public void testMatchesGoldenString() {
    SimpleOneBoxResults results = new SimpleOneBoxResults();
    
    results.setProviderName("PROVIDER_NAME");
    results.setQuery("QUERY");
    results.setTotalResults(99);
    results.setLink("LINK");

    ModuleResult moduleA = new ModuleResult();
    moduleA.setTitle("TITLE_A");
    moduleA.setUrl("URL_A");
    moduleA.putField("KEY_A", "VALUE_A");
    ModuleResult moduleB = new ModuleResult();
    moduleB.setTitle("TITLE_B");
    moduleB.setUrl("URL_B");
    moduleB.putField("KEY_B", "VALUE_B");
    moduleB.putField("KEY_Bx'", "VALUE_Bx");
    
    results.getResults().add(moduleA);
    results.getResults().add(moduleB);
    
    String goldenString =
      "<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n" + 
      "<OneBoxResults>\n" + 
      "  <provider>PROVIDER_NAME</provider>\n" + 
      "  <title>\n" + 
      "    <urlText>PROVIDER_NAME results for QUERY - 99</urlText>\n" + 
      "    <urlLink>LINK</urlLink>\n" + 
      "  </title>\n" + 
      "  <MODULE_RESULT>\n" + 
      "    <U>URL_A</U>\n" + 
      "    <Title>TITLE_A</Title>\n" + 
      "    <Field name=\"KEY_A\">VALUE_A</Field>\n" + 
      "  </MODULE_RESULT>\n" + 
      "  <MODULE_RESULT>\n" + 
      "    <U>URL_B</U>\n" + 
      "    <Title>TITLE_B</Title>\n" + 
      "    <Field name=\"KEY_Bx\'\">VALUE_Bx</Field>\n" + 
      "    <Field name=\"KEY_B\">VALUE_B</Field>\n" + 
      "  </MODULE_RESULT>\n" + 
      "</OneBoxResults>\n";
    
    assertEquals(goldenString, results.toString());
  }
  
}

